<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="店铺排队">
<!--suppress ALL -->
<form id="searchForm" class="form-panel">
    <ul class="panel-content">
        <li>
            <div>
                <div class="time-controls controls" id="select">

                </div>
                <label class="time-label control-label">起始日期：</label>

                <div class="time-controls controls">
                    <input name="startDate" class="input-small calendar" type="text" style="width: 80px;"><label>
                    &nbsp;-&nbsp;</label><input
                        name="endDate" class="input-small calendar" type="text" style="width: 80px;">
                </div>
                <button type="submit" class="button  button-primary" style="margin-left: 15px;">
                    查询
                </button>
                <a class="button button-danger" href="javascript:delFunction()" style="margin-left: 15px;">
                    批量删除
                </a>
            </div>
        </li>
    </ul>
</form>
<div id="grid"></div>
<script>
    var Grid = BUI.Grid,
            Store = BUI.Data.Store,
            columns = [
                {title: '序号', dataIndex: 'id', elCls: 'center', width: '5%'},
                {title: '店铺名称', dataIndex: 'storeName', elCls: 'center', width: '20%'},
                {
                    title: '当日大桌排队队数',
                    dataIndex: 'bigSeatAmount',
                    elCls: 'center',
                    width: '15%',
                    renderer: function (value) {
                        return value + '次';
                    }
                },
                {
                    title: '当日中桌排队队数',
                    dataIndex: 'middleSeatAmount',
                    elCls: 'center',
                    width: '15%',
                    renderer: function (value) {
                        return value + '次';
                    }
                },
                {
                    title: '当日小桌排队队数',
                    dataIndex: 'smallSeatAmount',
                    elCls: 'center',
                    width: '15%',
                    renderer: function (value) {
                        return value + '次';
                    }
                },
                {title: '日期', dataIndex: 'createTime', elCls: 'center', width: '15%'},
                {
                    title: '操作', dataIndex: 'id', elCls: 'center', width: '15%', renderer: function (value, data) {
                    var option1 = '<a href="${basepath}/rest/manage/lineup/toEdit?storeID=' + data.storeID + '&createTime='+data.createTime+'">查看</a>';
                        var option2 = '<a href="javascript:deleteOne(' + value + ')">删除</a>';
                    return option1 + "&nbsp;&nbsp;&nbsp;&nbsp;" + option2;
                }
                }
            ];
    var store = new Store({
                url: '/rest/manage/store/selectLineUpPage',
                autoLoad: true, //自动加载数据
                params: { //配置初始请求的参数
                    length: '10',
                    status: $("#status").val()
                },
                pageSize: 10,	// 配置分页数目
                root: 'list',
                totalProperty: 'total'
            }),
            grid = new Grid.Grid({
                render: '#grid',
                columns: columns,
                loadMask: true, //加载数据时显示屏蔽层
                store: store,
                plugins: [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
                // 底部工具栏
                bbar: {
                    pagingBar: true
                }
            });

    grid.render();
    /*--------------------------------模糊查询---------------------------------------------*/
    var form = new BUI.Form.HForm({
        srcNode: '#searchForm'
    }).render();

    form.on('beforesubmit', function (ev) {
        //序列化成对象
        var obj = form.serializeToObject();
        obj.start = 0; //返回第一页
        store.load(obj);
        return false;
    });
    /*--------------------------------模糊查询---------------------------------------------*/
    /*--------------------------------删除用户---------------------------------------------*/
    //删除选中的记录
    function delFunction() {
        BUI.Message.Confirm('确认要删除吗？', function () {
            var selections = grid.getSelection();
            var ids = new Array();
            for (var i = 0; i < selections.length; i++) {
                ids[i] = selections[i].id.toString()
            }
            $.ajax({
                type: "POST",
                url: "${basepath}/rest/manage/store/deleteLineups",
                dataType: "json",
                data: {
                    ids: ids
                },
                success: function (data) {
                    var obj = new Object();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }
    //删除单个用户
    function deleteOne(value) {
        BUI.Message.Confirm('确认要删除吗？', function () {
            $.ajax({
                type: 'POST',
                url: '${basepath}/rest/manage/store/deleteLineup',
                dataType: 'json',
                data: {
                    id: value
                },
                success: function () {
                    var obj = form.serializeToObject();
                    obj.start = 0; //返回第一页
                    store.load(obj);
                }
            });
        }, 'question');
    }
    /*--------------------------------删除用户---------------------------------------------*/
    //查询全部店铺
    $.ajax({
        type: 'GET',
        url: '${basepath}/rest/manage/store/selectAllList',
        dataType: 'json',
        success: function (data) {
            var selectList=data.data
            var selectHtml='<select name="storeID" class="input-normal" id="storeID"><option value = ""> 请选择店铺</option>';
            $.each(selectList,function(i,o){
                selectHtml+='<option value="'+ o.id+'">'+ o.name+'</option>';
            });
            selectHtml+='</select >';
            $("#select").html(selectHtml);
        }

    })
</script>

</@page.pageBase>
